﻿@page "/admin/role"
@attribute [Authorize]
@attribute [RolePermission]
@inherits ComponentDefault
@using ThingsGateway.Admin.Application
@namespace ThingsGateway.Admin.Razor
<div class="row h-100 g-0">

    <div class="col-0 col-sm-2 h-100">
        <Card IsShadow=true class="h-100" Color="Color.Primary">
            <BodyTemplate>
                <OrgTree ValueChanged="TreeChangedAsync"></OrgTree>
            </BodyTemplate>
        </Card>

    </div>
    <div class="col-12 col-sm-10 h-100 ps-2">
        <AdminTable @ref=table TItem="SysRole"
                    AutoGenerateColumns="true"
                    ShowAdvancedSearch=false
                    AllowResizing="true"
                    IsFixedHeader=true
                    IsMultipleSelect=true
                    EditDialogSize="Size.Large"
                    ShowSearch="false"
                    SearchModel=SearchModel
                    ShowExtendButtons=true
                    ShowDefaultButtons=true
                    ExtendButtonColumnWidth=500
                    OnQueryAsync="OnQueryAsync"
                    IsPagination=true
                    OnSaveAsync="Save"
                    OnDeleteAsync="Delete">

            <EditTemplate Context="context">
                <SysRoleEdit Model=context></SysRoleEdit>
            </EditTemplate>
            <RowButtonTemplate>
                <TableCellButton IsShow=@AuthorizeButton("授权用户") Size="Size.ExtraSmall" Color="Color.Success" Icon="fa-solid fa-people-roof" Text="@OperDescLocalizer["GrantUser"]" OnClick="()=>GrantUser(context.Id)" />
                <TableCellButton IsShow=@AuthorizeButton("授权资源") Size="Size.ExtraSmall" Color="Color.Warning" Icon="fa-solid fa-bars" Text="@OperDescLocalizer["GrantResource"]" OnClick="()=>GrantResource(context.Id)" />
                <TableCellButton IsShow=@AuthorizeButton("授权Api") Size="Size.ExtraSmall" Icon="fa fa-list" Text="@OperDescLocalizer["GrantApi"]" OnClick="()=>GrantApi(context.Id)" />
            </RowButtonTemplate>
        </AdminTable>
    </div>
</div>

@code {
    [NotNull]
    AdminTable<SysRole>? table { get; set; }
}
